import { defineStore } from "pinia";
import { ref } from "vue";
import { useCartStore } from "./cart";

export const useUserStore = defineStore(
  "user",
  () => {
    const token = ref("");
    const userId = ref("");
    const setUserInfo = (token1, userId1) => {
      token.value = token1;
      userId.value = userId1;
    };
    const isLogin = () => {
      if (token.value) {
        return true;
      } else {
        return false;
      }
    };
    const logout = () => {
      const cartStore = useCartStore();
      token.value = "";
      userId.value = "";
      cartStore.clearCart();
    };

    return { token, userId, setUserInfo, isLogin, logout };
  },
  {
    persist: true,
  }
);
